<!--  -->
<template>
  <div>获取code:{{ code }}</div>
</template>

<script lang='ts' setup>
import { reactive,toRefs,ref,onMounted} from 'vue'
import { useRoute,useRouter } from 'vue-router'
import { useAuthStore } from '../../store/authStore';

const store= useAuthStore();
const route = useRoute();
const router = useRouter();
const code=ref(route.query.code);
//使用code调接口 ，如果返回数据有token ,把token保存在pinia中

const login=async ()=>{

    console.log("扫码登录");
    

  const res=await  store.loginBycode(code.value as string);

  console.log("登录返回数据",res);

  if(res.data.token){
     
    router.push("/index");
  }
  else{ 


    console.log("账号未绑定",res);
    
      
  }

  

    
}

onMounted(()=>{
    login();
})


</script>
<style scoped>
</style>